<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="js/echarts.min.js"></script>
		<script src="js/jquery-3.4.0.min.js"></script>
		
		<!-- //展示访问量前十的IP地址(柱状图) -->
		<div id="time_visit" style="width: 600px;height: 400px;">
			<script type="text/javascript">
				var myEchar = echarts.init(document.getElementById('time_visit'));
				myEchar.showLoading();
				myUser = {
					"userid": 1
				}
				$.ajax({
					contentType: "application/json;charset=utf-8",
					type: "put",
					url: "http://localhost:8082/mylog/getTimes",
					data: JSON.stringify(myUser),
					dataType: "json",
					success: function(res) {
						console.log(res);
						if (res) {
							// var res1 = {
							// 	name: ["0点到9点","10点到14点","15点到20点","21点到24点"],
							// 	value: [0,0,0,0]
							// };
							var res1 = [{
								name:"0点到9点",
								value:"0"
							},{
								name:"10点到14点",
								value:"0"
							},{
								name:"15点到20点",
								value:"0"
							},{
								name:"21点到24点",
								value:"0"
							}
							]
							console.log(res1);
							
							for (var i in res){
								if (res[i].name >= "00:00:00" && res[i].name <= "09:59:59"){
									var x = parseInt(res1[0].value);
									var y = parseInt(res[i].value);
									res1[0].value = (x + y).toString();
								}
								else if (res[i].name >= "10:00:00" && res[i].name <= "14:59:59"){
									var x = parseInt(res1[1].value);
									var y = parseInt(res[i].value);
									res1[1].value = (x + y).toString();
								}
								else if (res[i].name >= "15:00:00" && res[i].name <= "20:59:59"){
									var x = parseInt(res1[2].value);
									var y = parseInt(res[i].value);
									res1[2].value = (x + y).toString();
								}
								else{
									var x = parseInt(res1[3].value);
									var y = parseInt(res[i].value);
									res1[3].value = (x + y).toString();
								}
							}
							
							console.log(res1);
							myEchar.hideLoading()
							myEchar.setOption({
								title: {
									text: '不同时间段用户访问量',
									left: 'center'
								},
								tooltip: {
									trigger: 'item'
								},
								legend: {
									orient: 'vertical',
									left: 'left'
								},
								series: [{
									type: 'pie',
									radius: '50%',
									data: res1,
									emphasis: {
										itemStype: {
											shadowBlur: 10,
											shadowOffsetX: 0,
											shadowColor: 'rgba{0, 0, 0, 0.5}'
										}
									}
								}]
							});
						}
					},
					error: function(errorMag) {
						alert("用户状态分析数据加载失败");
						myEchar.hideLoading();
					}
				});
				
				
			</script>
		</div>
	</head>
	<body>
		
	</body>
</html>
